function sectionChargeObj(tbodyID,data){
	this.tbodyObj = document.getElementById(tbodyID);
	this.count = 0;
	this.maxSize = 0;
	this.currentCount=0;
	this.data = data;
	this.optionText = new Array();
	this.optionValue = new Array();
	//this.data = "0,请选择;1,9002-刷卡;3,9001-积分;"
	this.initTbody = function(){
		this.addButton();
		var objArray = this.data.split(";");
		if(objArray.length >0)
		{
			for(var i = 0 ; i < objArray.length-1; i++)
			{
				var objs = objArray[i].split(",");
				this.optionText[i] = objs[1];
				this.optionValue[i] = objs[0];
			}
		}
		this.maxSize = objArray.length-1;
		this.addSection(1);
	};
	this.addSection = function(temp){
		if(temp == null)
		{
			this.getSelectOption();
		}
		var td1 = new newTD1().buildTD();
		var td2 = new newTD2(this).buildTD();
		var td3 = new newTD3().buildTD();
		var td4 = new newTD4(this.tbodyObj,this).buildTD();
		var tr1 = new newTR1(td1,td2,td3,td4).buildTR();
		this.tbodyObj.appendChild(tr1);
		this.currentCount++;
		setCurrentCountPayModel(this.currentCount);
		//document.writeln(this.tbodyObj.innerHTML);
	};
	this.deleteSection = function(){
		var trs = this.tbodyObj.getElementsByTagName("TR");
		var   len   =   trs.length;
		if(len>5)
		{
			 this.tbodyObj.removeChild(trs[len-2]);
			 this.currentCount--;
			 setCurrentCountPayModel(this.currentCount);
		}

	};
	this.addButton= function(){
		var td1 = new newTDWithTable(this).buildTD();
		var tr1 = new newHeadTR(td1).buildTR();
		this.tbodyObj.appendChild(tr1);
	};
	this.getSelectOption = function(){
		var trs = this.tbodyObj.getElementsByTagName("TR");
		if(trs == null){
			return null;
		}
		var currentTR =  trs[trs.length-1];
		var selectTD = currentTR.getElementsByTagName("TD")[3];
		var cselect = selectTD.getElementsByTagName("SELECT")[0];
		var index = cselect.selectedIndex;
		var a = this.optionText.slice(index,1);
	    var b = this.optionValue.slice(index,1);
		for(var i = 0 ; i < this.optionValue.length; i++)
		{
			//alert(this.optionText[i]+"\n"+this.optionValue[i]);
		}

	};
	this.getResult=function(){
		var str = "";
		var trs = this.tbodyObj.getElementsByTagName('TR');
		for(var i = 4 ; i < trs.length; i++)
		{
			   var selects  = trs[i].getElementsByTagName('SELECT')[0];
			   var inputObj = trs[i].getElementsByTagName('INPUT')[0];
			   str = str+inputObj.value+","+selects.options[selects.selectedIndex].value+";";
		}
		//document.writeln(this.tbodyObj.innerHTML);
		return str;
	}
}
function newTD1(){
	this.buildTD= function (){
		var mytd = document.createElement('td');
		mytd.className="aux_intable_td1";
		mytd.innerHTML="支付金额：";
		return mytd;
	}
}
function newTD2(sectionChargeObj){
	this._sectionChargeObj = sectionChargeObj;
	this.buildTD= function (){
		var mytd = document.createElement('td');
		mytd.className="aux_intable_require";
		var count = this._sectionChargeObj.count++;
		myinput = document.createElement('INPUT');
		//alert("count:"+count);
		myinput.type="text";myinput.id="mid_"+count;myinput.name="mname_"+count;
		myinput.className="required float-zero-right integer-decimal-range-18-2";
		myinput.size="16";myinput.maxLength="18"; myinput.align="right";myinput.setAttribute("afterInsert","tip"+count);
		myinputtext = document.createTextNode("元");
		myspan = document.createElement('span');
		myspan.id = "tip"+count;
		mytd.appendChild(myinput);
		mytd.appendChild(myinputtext);
		mytd.appendChild(myspan);
		return mytd;
	}
}
function newTD3(){
	this.buildTD= function (){
		var mytd = document.createElement('td');
		mytd.className="aux_intable_td1";
		mytd.innerHTML="支付交易码";
		return mytd;
	}
}
function newTD4(tbodyObj,sectionChargeObj){
	this._tbodyObj = tbodyObj;
	this._sectionChargeObj = sectionChargeObj;
	this.buildTD= function (){
		var mytd = document.createElement('td');
		mytd.className="aux_intable_require";
		var count = this._sectionChargeObj.count++;
		//alert("count:"+count);
		var myselect = document.createElement('SELECT');
		myselect.id="sid_"+count;
		myselect.name="sname_"+count;
		myselect.style.width ="110px";
		myselect.className="select-one-required";
		var _optionText = new Array();
		var _optionValue = new Array();
		//alert(this._sectionChargeObj.optionText.length);
		for(var i = 0 ; i < this._sectionChargeObj.optionText.length; i++)
		{
			_optionText[i] = this._sectionChargeObj.optionText[i];
			_optionValue[i] =  this._sectionChargeObj.optionValue[i];
			myselect.options[i] = new Option(_optionText[i], _optionValue[i]);
			//alert(_optionText[i]+"\n"+ _optionValue[i]);
		}
		mytd.appendChild(myselect);
		return mytd;
	}
}
function newTR1(tdObject1,tdObject2,tdObject3,tdObject4){
	this.tdObject1 = tdObject1;
	this.tdObject2 = tdObject2;
	this.tdObject3 = tdObject3;
	this.tdObject4 = tdObject4;
	this.buildTR = function(){
		var mytr = document.createElement('tr');
		mytr.appendChild(this.tdObject1);
		mytr.appendChild(this.tdObject2);
		mytr.appendChild(this.tdObject3);
		mytr.appendChild(this.tdObject4);
		return mytr;
	}
}
function newTable1(sectionChargeObj)
{
	this._sectionChargeObj = sectionChargeObj;
	this.buildTABLE = function(){
		var mytable = document.createElement('table');
		mytable.border="0";
		mytable.cellPadding="0";
		mytable.cellSpacing="0";
		mytable.setAttribute("_sectionCharge", this._sectionChargeObj);
		mytable.onclick = function(){
			if(isAllowAdd()){
				return false;
			}
			if(this._sectionCharge.currentCount < this._sectionCharge.maxSize)
				this._sectionCharge.addSection();
			//alert(this._sectionCharge.currentCount);
			//document.writeln(this._sectionCharge.tbodyObj.innerHTML);
		};
		var tr = mytable.insertRow();
		var td0 = tr.insertCell(0);
		td0.className ='buttonOffLeft';
		td0.id = "btn1_71";
		var td1 = tr.insertCell(1);
		td1.className = "buttonOffMiddle";
		td1.id="btn1_72";
		td1.onMouseOver="btn_change_over(7)";
		td1.onMouseOut="btn_change_out(7)";
		td1.onblur="btn_change(7)";
		td1.innerHTML = "<img src='images/ico_zengjia.gif' border='0' align='absbottom'/>增加支付方式";
		var td2 = tr.insertCell(2);
		td2.className = "buttonOffRight";
		td2.id="btn1_73";
		return mytable;
	}
}
function newTable2(sectionChargeObj)
{
	this._sectionChargeObj = sectionChargeObj;
	this.buildTABLE = function(){
		var mytable = document.createElement('table');
		mytable.border="0";
		mytable.cellPadding="0";
		mytable.cellSpacing="0";
		mytable.setAttribute("_sectionCharge", this._sectionChargeObj);
		mytable.setAttribute("id","deleteTable_01");
		mytable.onclick = function(){

			if(this._sectionCharge.currentCount <= this._sectionCharge.maxSize)
				this._sectionCharge.deleteSection();
			//alert(this._sectionCharge.currentCount);
		};
		var tr = mytable.insertRow();
		var td0 = tr.insertCell(0); td0.className ='buttonOffLeft'; td0.id = "btn1_81";
		var td1 = tr.insertCell(1); td1.className = "buttonOffMiddle";td1.id ="btn1_82";td1.onMouseOver="btn_change_over(8)"; td1.onMouseOut="btn_change_out(8)"; td1.onblur="btn_change(8)";
		td1.innerHTML = "<img src='images/ico_cancel.gif' border='0' align='absbottom'/>删除支付方式 "
		var td2 = tr.insertCell(2); td2.className = "buttonOffRight";td2.id="btn1_83";
		return mytable;
	}
}
function newTDWithTable(sectionChargeObj)
{
	this._sectionChargeObj = sectionChargeObj;
	this.buildTD = function(){
		var mytd = document.createElement('td');
		mytd.className="aux_titletable";
		mytd.colSpan="4";
		var mytable = document.createElement('table');
		mytable.border="0";
		mytable.cellPadding="0";
		mytable.cellSpacing="0";
		var mytr1 = mytable.insertRow();
		var mytd1= mytr1.insertCell(0);
		mytd1.innerHTML="<strong >支付方式 </strong>";
		var mytd2= mytr1.insertCell(1);
		mytd2.innerHTML="&nbsp;";
		var mytd3= mytr1.insertCell(2);
		mytd3.appendChild(new newTable1(this._sectionChargeObj).buildTABLE());
		var mytd4 = mytr1.insertCell(3);
		mytd4.width="4%";
		mytd4.innerHTML="&nbsp;";
		var mytd5 = mytr1.insertCell(4);
		mytd5.appendChild(new newTable2(this._sectionChargeObj).buildTABLE());
		mytd.appendChild(mytable);
		return mytd;
	}
}
function newHeadTR(tdObject1){
	this.tdObject1 = tdObject1;
	this.buildTR = function(){
		var mytr = document.createElement('tr');
		mytr.appendChild(this.tdObject1);
		return mytr;
	}
}

var CurrentCountPayModel=1;
function setCurrentCountPayModel(Count){
	CurrentCountPayModel=Count;
}

function getCurrentCountPayModel(){
	return CurrentCountPayModel;
}

